package com.changgou.goods.controller;


import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import com.changgou.goods.pojo.Sku;
import com.changgou.goods.service.SkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@CrossOrigin
@RequestMapping("/sku")
public class SkuController {
    @Autowired
    private SkuService skuService;

    /**
     * SKU编号查询返回对应的数据
     */

    @GetMapping(value = "/freight/{id}")
    public Result searchSku(@PathVariable("id") Integer id){

            Sku sku = skuService.searchById(id);
        if (sku!=null && !sku.equals("")) {
            return new Result(true, StatusCode.OK,"查询成功",sku);
        }
       return new Result(false,StatusCode.ERROR,"查询失败");

    }

    /**
     * SKU编号修改对应的数据
     */
    @GetMapping(value = "/skuAdd")
    public Result update(@RequestBody Sku sku){
         Integer index= skuService.ByIdUpdate(sku);
        if (index>0) {
            return new Result(true,StatusCode.OK,"更新成功");
        }
        return new Result(false,StatusCode.ERROR,"更新失败");
    }
}
